import { http } from "@/utils/http";
import { baseUrlApi, sseUrlApi } from "./utils";

export type PageResult = {
  success: boolean;
  data: {
    title?: string; //返回额外的题目用于展示
    /** 列表数据 */
    list: Array<any>;
    /** 总数 */
    total?: number;
  };
  errMsg: "";
};

export type DataResult = {
  success: boolean;
  data?: {};
  errMsg: "";
};

export type QuestionResult = {
  success: boolean;
  data?: {
    id: number;
    questionid: string;
    type: number;
    score: number;
    childIndex?: number;
    childId?: string;
    childType?: number;
    title?: string;
    childTitle?: string;
    choiceList?: Array<any>;
    answer?: any;
    description?: string;
  };
  errMsg: "";
};

export type PaperResult = {
  success: boolean;
  data?: Array<any>;
  times?: number;
  score?: number;
  errMsg: "";
};

export type QuestionAllScoreResult = {
  success: boolean;
  score0?: number;
  score1?: number;
  score2?: number;
  score3?: number;
  errMsg: "";
};

/////考试试卷管理//////////

export const querySimulatorExamList = (data?: object) => {
  return http.request<PageResult>(
    "post",
    baseUrlApi("querySimulatorExamList"),
    {
      data
    }
  );
};

export const addOrUpdateSimulatorExam = (data?: object) => {
  return http.request<DataResult>(
    "post",
    baseUrlApi("addOrUpdateSimulatorExam"),
    {
      data
    }
  );
};

export const deleteSimulatorExam = (data?: object) => {
  return http.request<DataResult>("post", baseUrlApi("deleteSimulatorExam"), {
    data
  });
};

export const onStartSimulatorExamByStudent = (data?: object) => {
  return http.request<PaperResult>(
    "post",
    baseUrlApi("onStartSimulatorExamByStudent"),
    {
      data
    }
  );
};

export const onStopSimulatorExamByStudent = (data?: object) => {
  return http.request<PaperResult>(
    "post",
    baseUrlApi("onStopSimulatorExamByStudent"),
    {
      data
    }
  );
};

export const findSimulatorPaperQuestionById = (data?: object) => {
  return http.request<QuestionResult>(
    "post",
    baseUrlApi("findSimulatorPaperQuestionById"),
    {
      data
    }
  );
};

export const updateStudentSimulatorExamAnswer = (data?: object) => {
  return http.request<DataResult>(
    "post",
    baseUrlApi("updateStudentSimulatorExamAnswer"),
    {
      data
    }
  );
};

export const onShowExamBySimulator = (data?: object) => {
  return http.request<PaperResult>(
    "post",
    baseUrlApi("onShowExamBySimulator"),
    {
      data
    }
  );
};

export const querySimulatorQuestionByType = (data?: object) => {
  return http.request<PageResult>(
    "post",
    baseUrlApi("querySimulatorQuestionByType"),
    {
      data
    }
  );
};

export const findSimulatorQuestionById = (data?: object) => {
  return http.request<QuestionResult>(
    "post",
    baseUrlApi("findSimulatorQuestionById"),
    {
      data
    }
  );
};

export const onShowExamErrorByType = (data?: object) => {
  return http.request<PaperResult>(
    "post",
    baseUrlApi("onShowExamErrorByType"),
    {
      data
    }
  );
};

export const querySimulatorQuestionAllScore = () => {
  return http.request<QuestionAllScoreResult>(
    "get",
    baseUrlApi("querySimulatorQuestionAllScore")
  );
};

export const closeSseClient = () => {
  return http.request<DataResult>("get", sseUrlApi("closeSse"));
};
